/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * newmedico.java
 *
 * Created on 30/Dez/2011, 15:33:19
 */

package vetclini;

import javax.swing.JFrame;
import org.jdesktop.application.Action;
import veterinario.Medico;

/**
 *
 * @author 2011101993 - Hugo Amaro
 * @author 2006130415 - Jorge Martins Alves
 */
public class newmedico extends javax.swing.JPanel {

    private VetCliniView pai;
    private JFrame minhaframe;

    /** Creates new form newmedico */
    public newmedico(JFrame fra) {
        initComponents();
        this.minhaframe = fra;
    }

    public void setPai(VetCliniView parent){
        this.pai = parent;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        nome = new javax.swing.JTextField();
        butaoConcluir = new javax.swing.JButton();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(vetclini.VetCliniApp.class).getContext().getResourceMap(newmedico.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        nome.setText(resourceMap.getString("nome.text")); // NOI18N
        nome.setName("nome"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(vetclini.VetCliniApp.class).getContext().getActionMap(newmedico.class, this);
        butaoConcluir.setAction(actionMap.get("clickedConcluir")); // NOI18N
        butaoConcluir.setText(resourceMap.getString("butaoConcluir.text")); // NOI18N
        butaoConcluir.setName("butaoConcluir"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(butaoConcluir)))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(butaoConcluir)
                .addContainerGap(27, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void clickedConcluir() {
        if (nome.getText().length()>0){
            Medico novoMedico = new Medico(nome.getText());
            pai.getClinica().addMedico(novoMedico);
            pai.updateLists();
            this.minhaframe.dispose();
        }else{
         janelaErro janelaErro = new janelaErro("Deve preencher o campo Nome");
         janelaErro.pack();
         janelaErro.setVisible(true);
         janelaErro.requestFocus();
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butaoConcluir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField nome;
    // End of variables declaration//GEN-END:variables

}
